package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class JDBCDemo7 {
    public static void main(String[] args) {

        try(Connection connection = DBUtil.getConnection()){
            Statement statement = connection.createStatement();
            String sql = "select s.name,s.gender, s.age, s.job,c.name,c.floor\n" +
                    "from student s\n" +
                    "join class c on s.class_id = c.id\n" +
                    "where c.name = '1年级1班'";
            ResultSet rs = statement.executeQuery( sql);
            System.out.println("学生名字——学生性别——学生年龄——学生职位——班级名——班级楼层");
            while (rs.next()){
                String sName = rs.getString("s.name");
                String sGender = rs.getString("s.gender");
                int sAge = rs.getInt("s.age");
                String sJob = rs.getString("s.job");
                String cName = rs.getString("c.name");
                int cFloor = rs.getInt("c.floor");
                System.out.println(sName + " , " + sGender + " , " + sAge + " , " + sJob + " , " + cName + " , " + cFloor);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
